package spring.cloud.tasks.api.database.service.impl;


import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import spring.cloud.tasks.api.database.entity.TaskConfigurationDto;
import spring.cloud.tasks.api.database.repository.TaskConfigurationDtoRepository;
import spring.cloud.tasks.api.database.service.TaskConfigurationDtoService;

import java.util.List;

@Service
public class TaskConfigurationDtoServiceImpl implements TaskConfigurationDtoService {


    @Autowired
    private TaskConfigurationDtoRepository taskConfigurationDtoRepository;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insert(TaskConfigurationDto taskConfigurationDto) throws RuntimeException {
        return taskConfigurationDtoRepository.insert(taskConfigurationDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int update(TaskConfigurationDto taskConfigurationDto) throws RuntimeException {
        return taskConfigurationDtoRepository.update(taskConfigurationDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int delete(Long id) throws RuntimeException {
        return taskConfigurationDtoRepository.delete(id);
    }

    @Override
    public void updatePreferExecutorIdList(TaskConfigurationDto taskConfigurationDto) throws RuntimeException {
        taskConfigurationDtoRepository.updatePreferExecutorIdList(taskConfigurationDto);
    }


    @Override
    public TaskConfigurationDto getTaskConfigurationDtoByNameSpaceAndTaskId(String nameSpace, String taskId) throws RuntimeException {
        return taskConfigurationDtoRepository.getTaskConfigurationDtoByNameSpaceAndTaskId(nameSpace, taskId);
    }

    @Override
    public List<TaskConfigurationDto> getTaskConfigurationDtoListByNameSpace(String nameSpace) throws RuntimeException {
        return taskConfigurationDtoRepository.getTaskConfigurationDtoListByNameSpace(nameSpace);
    }

    @Override
    public List<String> getTaskIdListByNameSpace(String nameSpace) throws RuntimeException {
        return taskConfigurationDtoRepository.getTaskIdListByNameSpace(nameSpace);
    }


}
